home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / c / ww_tv.exe / TVEDIT4.CPP < prev    next >
C/C++ Source or Header  |  1992-01-03  |  6KB  |  171 lines

  1. /****************************************************************************/
  2. /*                                                                          */
  3. /*                    Copyright (c) 1991 Primatech Inc.                     */
  4. /*                                                                          */
  5. /*                           All Rights Reserved                            */
  6. /*                                                                          */
  7. /****************************************************************************/
  8.  
  9.  
  10.  
  11. // $config$=/MTVEdit4.cpp
  12. //
  13. //  $NAME$:
  14. //          ..Module Overview
  15. //
  16. //  $GLOBAL PATHS$
  17. //          modules\all\TVEdit4.cpp
  18. //          modules\c++\TVEdit4.cpp
  19. //          objects\TEditorApp
  20. //
  21. //  $0$
  22. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  23. //
  24. //  Purpose:    To implement a macro recording a playback facility.  This is
  25. //              useful for testing and profiling the editor code.
  26. //
  27. //  Prototypes location:    $/SEE(.hpp)$
  28. //
  29. //  Other Information:
  30. //
  31. //  See also:       $/SEE()$
  32. //
  33. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  34.  
  35.  
  36. //$-1$
  37. #if 0
  38. //$1$
  39. /**** MODIFICATIONS HISTORY ****/
  40.  
  41. Created:        13 November 1991 by John L. Swartzentruber
  42.  
  43.  
  44. $SKIP START$
  45. #endif
  46.  
  47. /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
  48. /*+                                                                        +*/
  49. /*+                       I N C L U D E   F I L E S                        +*/
  50. /*+                                                                        +*/
  51. /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
  52. #include <stdio.h>
  53. #include <dos.h>
  54. #define Uses_TApplication
  55. #define Uses_TEvent
  56. #define Uses_TStatusLine
  57. #define Uses_TStatusDef
  58. #define Uses_TStatusItem
  59. #define Uses_TKeys;
  60. #include <tv.h>
  61.  
  62. #include "TVEdit.h"
  63.  
  64.  
  65.  
  66. //$SKIP END$
  67. //$2$
  68. /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
  69. /*+                                                                        +*/
  70. /*+       # D E F I N E S    C L A S S E S   and    T Y P E D E F S        +*/
  71. /*+                                                                        +*/
  72. /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
  73.  
  74.  
  75.  
  76. //$3$
  77. /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
  78. /*+                                                                        +*/
  79. /*+                E X T E R N A L    D E F I N I T I O N S                +*/
  80. /*+                                                                        +*/
  81. /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
  82.  
  83.  
  84. //$4$
  85. /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
  86. /*+                                                                        +*/
  87. /*+                  S T A T I C    D E F I N I T I O N S                  +*/
  88. /*+                                                                        +*/
  89. /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
  90.  
  91.  
  92.  
  93. //$END$
  94. /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
  95. /*+                                                                        +*/
  96. /*+          S T A T I C   F U N C T I O N   P R O T O T Y P E S           +*/
  97. /*+                                                                        +*/
  98. /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
  99.  
  100.  
  101. /* EJECT */
  102. //****************************************************************************
  103. //
  104. //      Function $NAME$:
  105. //                          TEditorApp::getEvent(TEvent&)
  106. //                                                                            $1$
  107. // 
  108. //      Purpose:    To get an event.  If recording, save the event in a 
  109. //                  file.  If playing back, read the event from the file.
  110. //                  If neither of the above, act like normal.
  111. //
  112. //      Return:     None
  113. //
  114. //      Other information:
  115. //
  116. //          This is just a quick and dirty hack.
  117. //
  118. //$0$
  119. //****************************************************************************
  120. void TEditorApp::getEvent(TEvent& event)
  121. //                                                                            $END$
  122. {
  123.     static FILE* macro_file = 0;
  124.     static enum MacroState {Nothing, Playing, Recording} state = Nothing;
  125.  
  126.     if (state == Playing && macro_file != 0) {
  127.         if (fread(&event, sizeof(event), 1, macro_file) != 1) {
  128.             fclose(macro_file);
  129.             macro_file = 0;
  130.             state = Nothing;
  131.  
  132.         } else {
  133.             putEvent(event);
  134.         }
  135.  
  136.         clearEvent(event);
  137.     }
  138.  
  139.     TApplication::getEvent(event);
  140.  
  141.     if (state == Recording && event.what != evNothing && macro_file != 0) {
  142.         // Don't write the record key that ends the recording.
  143.         if (event.what != evCommand || event.message.command != cmRecord) {
  144.             fwrite(&event, sizeof(event), 1, macro_file);
  145.         }
  146.     }
  147.  
  148.     switch (event.what) {
  149.         case evCommand:
  150.                 if (macro_file == 0 && event.message.command == cmPlay) {
  151.                     clearEvent(event);
  152.                     macro_file = fopen("KeyFile.dat", "rb");
  153.                     state = Playing;
  154.  
  155.                 // The record key is a toggle
  156.                 } else if (event.message.command == cmRecord) {
  157.                     clearEvent(event);
  158.  
  159.                     if (macro_file == 0) {
  160.                         macro_file = fopen("KeyFile.dat", "wb");
  161.                         state = Recording;
  162.                     } else {
  163.                         fclose(macro_file);
  164.                         macro_file = 0;
  165.                         state = Nothing;
  166.                     }
  167.                 }
  168.                 break;
  169.     }
  170. }
  171.